<template>
  <div class="front-index">
    <!-- 轮播图 -->
    <div class="carousel-container">
      <el-carousel height="400px" :autoplay="true" :interval="5000">
        <el-carousel-item v-for="(item, index) in carouselItems" :key="index">
          <img :src="item.imgUrl" alt="旅行图片" class="carousel-img" />
          <div class="carousel-caption">
            <h2>{{ item.title }}</h2>
            <p>{{ item.description }}</p>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    
    <!-- 功能区 -->
    <div class="features-section">
      <div class="container">
        <h2 class="section-title">欢迎加入我们的旅游爱好者社区</h2>
        <div class="features-grid">
          <div class="feature-card">
            <div class="feature-icon">
              <el-icon><Bell /></el-icon>
            </div>
            <h3>旅行公告</h3>
            <p>查看最新的旅行计划和社团公告</p>
            <router-link to="/front/travel-announcement" class="feature-link">立即查看</router-link>
          </div>
          <div class="feature-card">
            <div class="feature-icon">
              <el-icon><Ticket /></el-icon>
            </div>
            <h3>旅行申请</h3>
            <p>申请参加即将到来的旅行活动</p>
            <router-link to="/front/travel-application" class="feature-link">立即申请</router-link>
          </div>
          <div class="feature-card">
            <div class="feature-icon">
              <el-icon><User /></el-icon>
            </div>
            <h3>入团申请</h3>
            <p>成为旅游社团的正式成员</p>
            <router-link to="/front/member-application" class="feature-link">立即加入</router-link>
          </div>
          <div class="feature-card">
            <div class="feature-icon">
              <el-icon><ChatDotRound /></el-icon>
            </div>
            <h3>交流论坛</h3>
            <p>与其他旅游爱好者分享经验</p>
            <router-link to="/front/forum" class="feature-link">立即参与</router-link>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 最新活动 -->
    <div class="activities-section">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">最新旅行公告</h2>
          <router-link to="/front/travel-announcement" class="view-more">查看更多</router-link>
        </div>
        <div class="activities-list">
          <div class="activity-card" v-for="(activity, index) in latestNoticeData" :key="index">
            <img :src="activity.imgUrl" alt="活动图片" class="activity-img" />
            <div class="activity-info">
              <h3>{{ activity.title }}</h3>
              <p class="activity-time">{{ activity.createTime }}</p>
              <p class="activity-desc">{{ activity.summary }}</p>
              <router-link :to="'/front/travel-announcement/' + activity.id" class="activity-link">查看详情</router-link>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 热门话题 -->
    <div class="hot-topics-section">
      <div class="container">
        <div class="section-header">
          <h2 class="section-title">论坛热门话题</h2>
          <router-link to="/front/forum" class="view-more">查看更多</router-link>
        </div>
        <div class="topics-list" v-if="hotTopics.length > 0">
          <div class="topic-item" v-for="(topic, index) in hotTopics" :key="index">
            <div class="topic-rank">{{ index + 1 }}</div>
            <router-link :to="'/front/forum/' + topic.id" class="topic-title">{{ topic.title }}</router-link>
            <div class="topic-stats">
              <span class="views">{{ topic.viewCount }} 浏览</span>
              <span class="replies">{{ topic.replyCount }} 回复</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref ,computed} from 'vue'
import { Bell, Ticket, User, ChatDotRound } from '@element-plus/icons-vue'
import { hotForum } from '@/request/forum'
import { latestNotice } from '@/request/notice'
import { useGlobalStore } from '../store/userInfo'
const store = useGlobalStore()
const userInfo = computed(() => store.userInfo)


// 轮播图数据
const carouselItems = ref([
  {
    imgUrl: 'https://picsum.photos/id/10/1200/400',
    title: '春季赏花之旅',
    description: '探索全国各地的花海，感受春天的气息'
  },
  {
    imgUrl: 'https://picsum.photos/id/20/1200/400',
    title: '夏日海滩度假',
    description: '享受阳光沙滩，体验水上活动的乐趣'
  },
  {
    imgUrl: 'https://picsum.photos/id/30/1200/400',
    title: '秋季红叶观赏',
    description: '层林尽染，欣赏大自然的绚丽色彩'
  },
  {
    imgUrl: 'https://picsum.photos/id/40/1200/400',
    title: '冬季雪景之旅',
    description: '银装素裹，体验冬日的浪漫与纯净'
  }
])
//imgUrl: 'https://picsum.photos/id/50/300/200'
const latestNoticeData = ref([])

// 获取最新的三条公告
const getLatestNotice = async () => {
  try {
    const res = await latestNotice()
    latestNoticeData.value = res
    latestNoticeData.value.forEach(item => {
      item.imgUrl = `https://picsum.photos/id/${item.id*10}/300/200`
    })
    console.log('最新的三条公告:',latestNoticeData.value)
  } catch (error) {
    console.error('获取最新的三条公告失败:', error)
  }
}
getLatestNotice();

// 热门话题数据
const hotTopics = ref([])

// 获取热门话题
const getHotForum = async () => {
  try {
    const res = await hotForum()
    hotTopics.value = res
  } catch (error) {
    console.error('获取热门话题失败:', error)
  }
}

// 调用获取热门话题函数
getHotForum()
</script>

<style scoped>
.front-index {
  width: 100%;
}

/* 轮播图样式 */
.carousel-container {
  position: relative;
  width: 100%;
  height: 400px;
  overflow: hidden;
}

.carousel-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.carousel-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px;
  background: rgba(0, 0, 0, 0.5);
  color: white;
}

.carousel-caption h2 {
  margin: 0 0 10px 0;
  font-size: 32px;
}

.carousel-caption p {
  margin: 0;
  font-size: 16px;
}

/* 功能区样式 */
.features-section {
  padding: 60px 0;
  background-color: #f5f5f5;
}

.container {
  width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.section-title {
  text-align: center;
  margin-bottom: 40px;
  font-size: 28px;
  color: #333;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.feature-card {
  background-color: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  text-align: center;
  transition: transform 0.3s, box-shadow 0.3s;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.feature-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  background-color: #e6f7ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #1890ff;
}

.feature-card h3 {
  margin: 0 0 10px 0;
  font-size: 18px;
  color: #333;
}

.feature-card p {
  margin: 0 0 20px 0;
  color: #666;
  font-size: 14px;
}

.feature-link {
  display: inline-block;
  color: #1890ff;
  text-decoration: none;
  font-size: 14px;
}

.feature-link:hover {
  text-decoration: underline;
}

/* 活动区样式 */
.activities-section {
  padding: 60px 0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.view-more {
  color: #1890ff;
  text-decoration: none;
  font-size: 14px;
}

.activities-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.activity-card {
  background-color: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
}

.activity-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.activity-img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.activity-info {
  padding: 20px;
}

.activity-info h3 {
  margin: 0 0 10px 0;
  font-size: 18px;
  color: #333;
}

.activity-time {
  margin: 0 0 10px 0;
  color: #1890ff;
  font-size: 14px;
}

.activity-desc {
  margin: 0 0 20px 0;
  color: #666;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.activity-link {
  display: inline-block;
  color: #1890ff;
  text-decoration: none;
  font-size: 14px;
}

.activity-link:hover {
  text-decoration: underline;
}

/* 热门话题样式 */
.hot-topics-section {
  padding: 60px 0;
  background-color: #f5f5f5;
}

.topics-list {
  background-color: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.topic-item {
  display: flex;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid #f0f0f0;
}

.topic-item:last-child {
  border-bottom: none;
}

.topic-rank {
  width: 30px;
  height: 30px;
  background-color: #1890ff;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  font-size: 14px;
  font-weight: bold;
}

.topic-title {
  flex: 1;
  color: #333;
  text-decoration: none;
  font-size: 16px;
}

.topic-title:hover {
  color: #1890ff;
}

.topic-stats {
  display: flex;
  gap: 20px;
  font-size: 14px;
  color: #999;
}
</style>